package cn.wolfcode.shop.controller;

import cn.wolfcode.shop.domain.Property;
import cn.wolfcode.shop.domain.SkuProperty;
import cn.wolfcode.shop.service.ICatalogService;
import cn.wolfcode.shop.service.ISkuPropertyService;
import cn.wolfcode.shop.vo.JSONResultVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by wolfcode on 2018/8/17.
 */
@Controller
public class SkuPropertyController {
    @Reference
    private ICatalogService catalogService;
    @Reference
    private ISkuPropertyService skuPropertyService;
    @RequestMapping("/skuProperty")
    public String skuPropertyPage(Model model){
        model.addAttribute("allCatalog",catalogService.selectAllFromCache());
        return "skuProperty/skuProperty";
    }
    @RequestMapping("/skuProperty/get/{catalogId}")
    public String skuPropertyListPage(@PathVariable("catalogId") Long catalogId,Model model){
        model.addAttribute("skuPropertyList",skuPropertyService.queryByCatalogId(catalogId));
        return "skuProperty/skuProperty_list";
    }
    @RequestMapping("skuProperty/save")
    @ResponseBody
    public JSONResultVo saveOrUpdata(SkuProperty skuProperty){
        JSONResultVo vo = new JSONResultVo();
        try{
            skuPropertyService.saveOrUpdate(skuProperty);
        }catch(Exception e){
            e.printStackTrace();
            vo.setErrorMsg(e.getMessage());
        }
        return vo;
    }
    @RequestMapping("skuProperty/delete/{skuPropertyId}")
    @ResponseBody
    public JSONResultVo delete(@PathVariable("skuPropertyId") Long skuPropertyId){
        JSONResultVo vo = new JSONResultVo();
        try{
            skuPropertyService.delete(skuPropertyId);
        }catch(Exception e){
            e.printStackTrace();
            vo.setErrorMsg(e.getMessage());
        }
        return vo;
    }
}
